<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<style>

</style>
<body>
<h1 id="countdown"></h1>
<script>
    //? 设置倒计时的目标日期和时间
    const targetDate = new Date('2024-01-01T00:00:00').getTime();
    //? 更新倒计时
    function updateCountdown() {
        const now = new Date().getTime();
        const distance = targetDate - now;
        //? 计算天、小时、分钟和秒
        const days = Math.floor(distance / (1000 * 60 * 60 * 24));
        const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
        const seconds = Math.floor((distance % (1000 * 60)) / 1000);
        //? 将倒计时显示在页面上
        document.getElementById('countdown').innerHTML = `${days} 天 ${hours} 小时 ${minutes} 分钟 ${seconds} 秒`;
        //? 当倒计时结束时显示特定信息
        if (distance < 0) {
            clearInterval(countdownInterval);
            document.getElementById('countdown').innerHTML = '倒计时结束！';
        }
    }
    //? 每秒钟更新倒计时
    const countdownInterval = setInterval(updateCountdown, 1000);
</script>
</body>
</html>
